package cn.uniquetech.esf;


import cn.uniquetech.util.FileUtil;

public class GenServiceUtil {
	// service 生成接口
	private static String parseServiceInterface(String tableName, String tableRemarks) {
		String servicePackage = GenerateCodeSqlServer.PACKAGENAME + ".service";
		StringBuffer sb = new StringBuffer();
		sb.append("package " + servicePackage + ";\r\n");
		String clazz = tableName;
		sb.append("import cn.uniquesoft.service.base.IBaseService;\r\n");
		sb.append("\r\n/**" + tableRemarks + "**/");
		sb.append("\r\npublic interface I" + clazz + "Service extends IBaseService" + "{\r\n\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, "I" + clazz + "Service.java", sb.toString());
		return sb.toString();
	}

	// service 生成实现类
	private static String parseServiceClass(String tableName, String tableRemarks) {
		String servicePackage = GenerateCodeSqlServer.PACKAGENAME + ".service.impl";
		StringBuffer sb = new StringBuffer();
		sb.append("package " + servicePackage + ";\r\n\r\n");
		String clazz = tableName;
		sb.append("import org.springframework.stereotype.Service;\r\n");
		sb.append("import cn.uniquesoft.service.I" + clazz + "Service;");
		sb.append("\r\n\r\n");
		sb.append("/**" + tableRemarks + "**/\r\n");
		sb.append("@Service");
		sb.append("\r\n");
		sb.append("public class " + clazz + "ServiceImpl extends BaseServiceImpl implements I" + clazz + "Service" + " {\r\n\r\n");
		sb.append("\tpublic " + clazz + "ServiceImpl() {\r\n");
		sb.append("\t\tsuper();\r\n");
		sb.append("\t\tthis.mapper = \"" + clazz + "Mapper\";\r\n");
		sb.append("\t}\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, clazz + "ServiceImpl.java", sb.toString());
		return sb.toString();
	}

	public static String parseService(String tableName, String tableRemarks) {
		String str = parseServiceInterface(tableName, tableRemarks);
		str = parseServiceClass(tableName, tableRemarks);
		return str;
	}
}
